Completed
Push — develop ( e0a4fd...b477c5 )
by Bjarn
13s queued 11s
created

Homebrew.uninstall   A

Complexity

Conditions 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
dl 0
loc 17
rs 9.9
c 0
b 0
f 0
1
import execa from 'execa'
2
import PackageManager from '../packageManager'
3
4
class Homebrew extends PackageManager {
5
    alias = 'brew'
6
    name = 'Homebrew'
7
    path = '/usr/local/bin/brew'
8
9
    /**
10
     * Install a package. In case of brew, the cask variable should be true of it ain't a formula but a cask.
11
     *
12
     * @param pkg
13
     * @param cask
14
     */
15
    async install(pkg: string, cask = false): Promise<boolean> {
16
        let args: string[] = ['install', pkg]
17
18
        if (cask) {
19
            args = ['install', 'cask', pkg]
20
        }
21
22
        const {stdout} = await execa('brew', args, {shell: true})
23
24
        return stdout.includes(pkg)
25
    }
26
27
    /**
28
     * Uninstall a package. In case of brew, the cask variable should be true of it ain't a formula but a cask.
29
     *
30
     * @param pkg
31
     * @param cask
32
     */
33
    async uninstall(pkg: string, cask = false): Promise<boolean> {
34
        let args: string[] = ['remove', pkg]
35
36
        if (cask) {
37
            args = ['remove', 'cask', pkg]
38
        }
39
40
        const {stdout} = await execa('brew', args, {shell: true})
41
42
        return stdout.includes(pkg)
43
    }
44
45
    /**
46
     * Check if the pkg is installed.
47
     *
48
     * @param pkg
49
     */
50
    async packageIsInstalled(pkg: string): Promise<boolean> {
51
        const {stdout} = await execa('brew', ['list', '--formula'], {shell: true})
52
53
        return stdout.includes(pkg)
54
    }
55
56
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
    remove(pkg: string): Promise<boolean> {
58
        return Promise.resolve(false)
59
    }
60
61
    update(): Promise<boolean> {
62
        return Promise.resolve(false)
63
    }
64
65
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
    upgrade(pkg: string | undefined): Promise<boolean> {
67
        return Promise.resolve(false)
68
    }
69
}
70
71
export default Homebrew